package com.framework.rocketmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.common.message.MessageExt;

import java.nio.charset.StandardCharsets;

/**
 * 描述：
 * 默认消费者工具类
 *  这只是一个样例
 * @author xianggj
 * @Date 2021/10/13 17:22
 **/
@Slf4j
public class DefaultConsumer extends Consumer {


    @Override
    protected void consume(MessageExt msgExt, ConsumeConcurrentlyContext context) throws Exception {
        String msg = new String(msgExt.getBody(), StandardCharsets.UTF_8);
        log.info("msg:" + msg);
//        EntityDTO entityDTO = null;
//        try {
//            entityDTO = JSON.parseObject(new String(msg.getBody(), ), EntityDTO.class);
//            doSomething(entityDTO);
//        } catch (Exception e) {
//            logger.error("doSomething fail, the body: {}", entityDTO == null ? null : entityDTO.toString());
//        }
    }

    @Override
    protected MQConfig getMQConfig() {
        return new MQConfig(MQConfig.TOPIC);
    }

    @Override
    protected String getGroupName() {
        return "default-demo";
    }
}
